#include <iostream>
#include "fenTree.h"

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> data(n);
    fenTree<int> invs(n);
    std::cout << "Write elements from 0 to " << n - 1 << ":\n";
    for (size_t i = 0; i < n; ++i)
    {
        std::cin >> data[i];
    }

    int invCount = 0;
    for (size_t i = 0; i < n; ++i)
    {
        invCount += invs.sum(data[i] + 1, n);
        invs.inc(data[i], 1);
    }

    std::cout << invCount << "\n";

    return 0;
}
